package com.itheima.service;

import cn.hutool.core.util.ObjectUtil;
import com.itheima.api.SmsFlashPromotionProductRelationApi;
import com.itheima.pojo.SmsFlashPromotionProductRelation;
import com.itheima.vo.PageResult;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author Hakuna Matata
 * @date 2022-10-12-20:56
 */
@Service
public class FlashProductRelationService {

    @DubboReference
    private SmsFlashPromotionProductRelationApi flashPromotionProductRelationApi;

    //批量选择商品添加关联
    public void create(SmsFlashPromotionProductRelation flashPromotionProductRelation) {
        flashPromotionProductRelationApi.create(flashPromotionProductRelation);
    }

    //删除关联
    public void delete(Long id) {
        flashPromotionProductRelationApi.delete(id);
    }

    //修改关联信息
    public void update(Long id, SmsFlashPromotionProductRelation flashPromotionProductRelation) {
        //查看该id下的是否存在, 存在就更新
        SmsFlashPromotionProductRelation relation = flashPromotionProductRelationApi.findById(id);
        if (ObjectUtil.isNotNull(relation)) {
            flashPromotionProductRelationApi.update(id, flashPromotionProductRelation);
        }
    }

    //分页查询不同场次关联及商品信息
    public PageResult list(Integer flashPromotionId, Integer flashPromotionSessionId, Integer pageNum, Integer pageSize) {

        return flashPromotionProductRelationApi.list(flashPromotionId, flashPromotionSessionId, pageNum, pageSize);
    }

    //获取管理商品促销信息
    public SmsFlashPromotionProductRelation getRelationInfo(Long id) {
        return flashPromotionProductRelationApi.findById(id);
    }
}
